<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"www.lixiaofei.cn","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":true,"storage":true,"lazyload":true,"nav":{"valine":{"order":-1}}},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="通过最近的一个小示例，介绍一下分布式系统的特点，和简单实现方式,目的在于使用高级的思路解决实际的问题。">
<meta property="og:type" content="article">
<meta property="og:title" content="用分布式系统思路解决资源受限问题">
<meta property="og:url" content="http://www.lixiaofei.cn/2017-05-11-distributed-thinking/index.html">
<meta property="og:site_name" content="管窥程序">
<meta property="og:description" content="通过最近的一个小示例，介绍一下分布式系统的特点，和简单实现方式,目的在于使用高级的思路解决实际的问题。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://blog.lixiaofei.cn/wp-content/uploads/2017/05/Image.png">
<meta property="og:image" content="http://blog.lixiaofei.cn/wp-content/uploads/2017/05/Image2.png">
<meta property="article:published_time" content="2017-05-11T15:02:45.000Z">
<meta property="article:modified_time" content="2020-07-24T07:29:39.238Z">
<meta property="article:author" content="太阳雪">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://blog.lixiaofei.cn/wp-content/uploads/2017/05/Image.png">

<link rel="canonical" href="http://www.lixiaofei.cn/2017-05-11-distributed-thinking/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>用分布式系统思路解决资源受限问题 | 管窥程序</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">管窥程序</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Today is a gift</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/alisx" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://www.lixiaofei.cn/2017-05-11-distributed-thinking/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="太阳雪">
      <meta itemprop="description" content="总结 技术 思考 想法">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="管窥程序">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          用分布式系统思路解决资源受限问题
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-05-11 23:02:45" itemprop="dateCreated datePublished" datetime="2017-05-11T23:02:45+08:00">2017-05-11</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-24 15:29:39" itemprop="dateModified" datetime="2020-07-24T15:29:39+08:00">2020-07-24</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%9C%AA%E5%88%86%E7%B1%BB/" itemprop="url" rel="index"><span itemprop="name">未分类</span></a>
                </span>
            </span>

          
            <span id="/2017-05-11-distributed-thinking/" class="post-meta-item leancloud_visitors" data-flag-title="用分布式系统思路解决资源受限问题" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2017-05-11-distributed-thinking/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2017-05-11-distributed-thinking/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>通过最近的一个小示例，介绍一下分布式系统的特点，和简单实现方式,目的在于使用高级的思路解决实际的问题。</p>
<a id="more"></a>
<h2 id="a-class-reference-link-name-lt-strong-gt-背景-lt-strong-gt-：-a-背景："><a class="reference-link" name="&lt;strong&gt;背景&lt;/strong&gt;："></a><strong>背景</strong>：</h2>
<p>有个任务，将csv格式的数据读入，加工处理，最后输出一个或者多个excel文件。</p>
<h2 id="a-class-reference-link-name-lt-strong-gt-问题-lt-strong-gt-：-a-问题："><a class="reference-link" name="&lt;strong&gt;问题&lt;/strong&gt;："></a><strong>问题</strong>：</h2>
<p>为了方便使用，将系统迁移至VPS，由于VPS新能问题(配置1核，1G，别问我为啥不升级配置)，处理时大文件时，占用内存过多，程序会崩溃</p>
<h2 id="a-class-reference-link-name-lt-strong-gt-目标-lt-strong-gt-：-a-目标："><a class="reference-link" name="&lt;strong&gt;目标&lt;/strong&gt;："></a><strong>目标</strong>：</h2>
<p>在资源受限的情况下，让程序正常使用</p>
<h2 id="a-class-reference-link-name-lt-strong-gt-分析-lt-strong-gt-：-a-分析："><a class="reference-link" name="&lt;strong&gt;分析&lt;/strong&gt;："></a><strong>分析</strong>：</h2>
<ol>
<li>发现程序崩溃是由于生成大的Excel文件引起的</li>
<li>单独生成一个大文件不会出现崩溃，但连续生成3个以上的文件会崩溃</li>
<li>发现系统崩溃时，程序内存占比达到37%，小于37%可以正常运行</li>
<li>单独执行有大概2~4分钟，内存占比才会下降</li>
<li>处理此类任务每月不超过2次</li>
<li>用户对任务的结果的期待不能超过24小时</li>
</ol>
<h2 id="a-class-reference-link-name-lt-strong-gt-方案-lt-strong-gt-：-a-方案："><a class="reference-link" name="&lt;strong&gt;方案&lt;/strong&gt;："></a><strong>方案</strong>：</h2>
<p>根据分析，可以采用时间换新能的方式，另外还可以主动释放内存。具体方案是：将生成多个大Excel文件的过程分解为多个一次只生成一个Excel文件的过程，即子过程，没执行一个子过程，主动调用垃圾回收方法，而要执行一个子过程时，先看内存占比是否小于37%，是执行，否放弃执行，等待下次执行。于是打算采用异步、分布式处理的方式。</p>
<h2 id="a-class-reference-link-name-lt-strong-gt-过程-lt-strong-gt-：-a-过程："><a class="reference-link" name="&lt;strong&gt;过程&lt;/strong&gt;："></a><strong>过程</strong>：</h2>
<ul>
<li>
<p>基本功能：</p>
<ol>
<li>主任务拆分(生产者)<br>
主任务要具**<em>有可拆分性</em>**，就是可以拆分成简单子任务，子任务之间的关联度要尽量小，否则就不能并行执行了，比如任务A，拆分成a，b，c三个子任务，b依赖于a的结果，c依赖于b的结果，那么子任务只能按a、b、c的顺来执行，无法并行，分布式反而会让处理更复杂更慢；还有后续任务需要明确知道前序任务以及前序任务的结果，所以后续任务执行前需要更多的时间和资源创建执行环境。对于只想让拆分任务，分步执行的，子任务间的关联度大小影响不大。处理中，使用了循环，生成多个Excel文件，所以很容易拆分成子任务，且子任务之间没有关联。</li>
<li>子任务队列(产品和篮子)<br>
队列是分布式方案中很常用的数据结构，方便先进先出，同时方便调度算法的实现。队列的实现方式很多，其实很简单，这里用库表作为存储，每次获取id最小的记录，实现先进先出的效果。 队列中存放什么是关键，需要充分考虑子任务执行中用到的数据，执行方法，尤其是环境变量，很容易遗漏。程序中，处理完所有的子任务，需要将结果打包成zip文件，zip文件名是个环境变量，也需要保存在记录中，见4结果合成。</li>
<li>队列调度(消费者)<br>
简单说就是从队列中获取记录的方法，比如一次获取几个，要不要考虑优先级，怎样才能避免一个任务分配给多个执行者等等，就简单的就是每次只取一条。调度算法将拿到的记录分配给执行者。一般对于队列来说，除了队列就从队列中删除了，我采用了库表做存储，并且想作为执行日志来用，所以采用标记的方式，即获取到的记录打上已分配的标签，表示这个记录已经被取走，调度程序就不会再分配它了。</li>
<li>结果组合分布式执行必须要有这一步，1为表示主任务完成了，2 将子任务执行的结果组合起来作为主任务的结果。由于分布式异步执行的原因，不能预测主任务的完成时间，也无法预知最后一个子任务是谁，执行者执行完一个子任务后，需要看一下自己是否是最后一个完成的，如果是就调用结果组合方法。程序中，合成方法会将所有子任务产生的文件，打成zip包，最后一个子任务负责打包，由于不知道谁是最后一个，所以每个子任务都会zip包的名字。好傻哈哈，如果任务分配后还需要变更某些变量时，就得更新每个子任务记录了，更优雅的做法是设计一个主任务记录，将zip包文件名，以及和主任务相关的数据记录在这里，当子任务需要时从这里拿就行，不过为了方便实现，没有过多优雅。</li>
</ol>
</li>
<li>
<p>还需考虑：</p>
<ol>
<li>持久化 —— <strong>断点续传</strong><br>
断点续传的概念来自于迅雷下载，下载一个大文件，到一半，电脑关机了，下次打开，还可以从关机时下载到的地方继续下载，不必重新开始。分布式处理可能时间长，环境复杂，服务器宕机、重启，服务崩溃等情况不可避免，所以需要记录执行的位置，以便系统恢复后不必重新开始。在恢复执行中，有个有意思的地方，先看子任务处理状态图：<img src="http://blog.lixiaofei.cn/wp-content/uploads/2017/05/Image.png" alt=""><br>
当状态是已分配，系统崩溃了，在执行时，调度程序就会认为这个记录正在被执行，但实际上执行者早随系统死了。于是这个主任务就永远执行不完。其实解决方法很简单：当系统启动时，确认没有任务被执行了，需要对状态为已分配的记录设置状态为未分配，即<img src="http://blog.lixiaofei.cn/wp-content/uploads/2017/05/Image2.png" alt=""></li>
<li>进度反馈这个其实挺有个必要的，因为不知道任务什么时候能结束，有个进度提示会人性化很多，当然实现很简单，已完成的子任务数/子任务总数就可以，这里要注意什么叫已完成的子任务数，应该是状态不是未分配的任务个数，这个好处在于不用区分已分配，已完成和存在错误者三个状态了，即将他们归于一类，这样方便些，可能有些不精确的地方，但这里只是显示个大概，所以越简单越好。</li>
<li>执行中出了问题不能保证所有的任务都按预想的那样执行，所以问题总会有的，出了问题需要记录下原因，以便查看和修正，至于是否终止掉整个任务，就看具体场景来定，在我的例子中，子任务之间没有关联，所以就没必要终止任务的执行。无论才有什么策略，都需要在主任务上有所返回，这样就能让使用者及时发现问题。当然更好的做法是有个运维接口，出现问题及时报告给运维人员。我的实现中，会见错误信息记录在子任务记录上，并且设置记录的状态为出错，相当于同时充当了日志记录。</li>
</ol>
</li>
</ul>
<h2 id="a-class-reference-link-name-概括下要点-a-概括下要点"><a class="reference-link" name="概括下要点:"></a>概括下要点:</h2>
<ol>
<li>任务可拆分</li>
<li>队列调度</li>
<li>断点恢复</li>
<li>结果组合</li>
<li>进度反馈</li>
<li>错误处理</li>
</ol>
</div>
    </div>

    
    
    

      <footer class="post-footer">

        

			<div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/wechat-qcode.png" alt="太阳雪 wechat" style="width: 200px; max-width: 100%;"/>
    <div>关注我，获得更多精彩内容</div>
</div>

        
		
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2017-03-37-impression-of-one-than-myriad/" rel="prev" title="读一句顶一万句有感">
      <i class="fa fa-chevron-left"></i> 读一句顶一万句有感
    </a></div>
      <div class="post-nav-item">
    <a href="/2018-05-10-markdown/" rel="next" title="Hexo Markdown 语法说明">
      Hexo Markdown 语法说明 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#a-class-reference-link-name-lt-strong-gt-背景-lt-strong-gt-：-a-背景："><span class="nav-number">1.</span> <span class="nav-text">背景：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a-class-reference-link-name-lt-strong-gt-问题-lt-strong-gt-：-a-问题："><span class="nav-number">2.</span> <span class="nav-text">问题：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a-class-reference-link-name-lt-strong-gt-目标-lt-strong-gt-：-a-目标："><span class="nav-number">3.</span> <span class="nav-text">目标：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a-class-reference-link-name-lt-strong-gt-分析-lt-strong-gt-：-a-分析："><span class="nav-number">4.</span> <span class="nav-text">分析：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a-class-reference-link-name-lt-strong-gt-方案-lt-strong-gt-：-a-方案："><span class="nav-number">5.</span> <span class="nav-text">方案：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a-class-reference-link-name-lt-strong-gt-过程-lt-strong-gt-：-a-过程："><span class="nav-number">6.</span> <span class="nav-text">过程：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#a-class-reference-link-name-概括下要点-a-概括下要点"><span class="nav-number">7.</span> <span class="nav-text">概括下要点:</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="太阳雪"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">太阳雪</p>
  <div class="site-description" itemprop="description">总结 技术 思考 想法</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">88</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">47</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">太阳雪</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>















  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'teRj7yeJj0xpfGKLJ5uFdbIu-gzGzoHsz',
      appKey     : '3uie0p1nxouCCnkjiXTEBeLd',
      placeholder: "您的关注是我的动力",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
